📚 SAP Business One SDK Help

Add a payment line sample
See Also

Description

The following sample code shows how to add a new payment line.
Private Sub cmdTest_Click()
   On Error GoTo ErrorHandler
   Dim vCompany As SAPbobsCOM.Company

   'create company object
   Set vCompany = New SAPbobsCOM.Company

   'set paras for connection
   vCompany.CompanyDB = "SBODemo_US"
   vCompany.Password = "manager"
   vCompany.UserName = "manager"
   vCompany.Server = "(local)"

   'connect to database server
   If (0 <> vCompany.Connect()) Then
      MsgBox "Failed to connect"
      Exit Sub
   End If

   Dim nErr As Long
   Dim errMsg As String

   'Set the object's properties
   Dim vPay As SAPbobsCOM.Payments
   Set vPay = vCompany.GetBusinessObject(oIncomingPayments)
   vPay.Address = "622-7"
   vPay.ApplyVAT = 1
   vPay.CardCode = "D10006"
   vPay.CardName = "Card D10004"
   vPay.CashAccount = "288000"
   vPay.CashSum = 0 '5620.85
   vPay.CheckAccount = "280001"
   vPay.ContactPersonCode = 2
   vPay.DocCurrency = "Eur"
   vPay.DocDate = Now
   vPay.DocRate = 0
   vPay.DocTypte = 0
   vPay.HandWritten = 0
   vPay.JournalRemarks = "Incoming - D10004"
   vPay.LocalCurrency = 0
   vPay.Printed = 0
   vPay.Reference1 = 14
   vPay.Series = 0
   vPay.SplitTransaction = 0
   vPay.TaxDate = Now
   vPay.TransferAccount = "10100"
   vPay.TransferDate = Now
   vPay.TransferSum = 0 '

   vPay.Invoices.AppliedFC = 0
   vPay.Invoices.AppliedSys = 5031.2
   vPay.Invoices.DocEntry = 8
   vPay.Invoices.DocLine = 0
   vPay.Invoices.DocRate = 0
   vPay.Invoices.InvoiceType = it_Invoice
   vPay.Invoices.LineNum = 0
   vPay.Invoices.SumApplied = 5031.2


   vPay.Checks.AccounttNum = "384838"
   vPay.Checks.BankCode = "CB"
   vPay.Checks.Branch = "Branch"
   vPay.Checks.CheckNumber = 3838383
   vPay.Checks.CheckSum = 4031.2
   vPay.Checks.Currency = "Eur"
   vPay.Checks.Details = "test1"
   vPay.Checks.DueDate = CDate("31/12/2002")
   vPay.Checks.LineNum = 0
   vPay.Checks.Trnsfrable = 0
   Call vPay.Checks.Add
   Call vPay.Checks.SetCurentLine(1)
   vPay.Checks.AccounttNum = "384838"
   vPay.Checks.BankCode = "CB"
   vPay.Checks.Branch = "Branch"
   vPay.Checks.CheckNumber = "3838383"
   vPay.Checks.CheckSum = 1000
   vPay.Checks.Currency = "EUR"
   vPay.Checks.Details = "test2"
   vPay.Checks.DueDate = Now
   vPay.Checks.LineNum = 1
   vPay.Checks.Trnsfrable = 0
   If (vPay.Add() <> 0) Then
       MsgBox ("Failed to add a payment")
   End If

   'check for errors
   Call vCompany.GetLastError(nErr, errMsg)
   If (0 <> nErr) Then
       MsgBox ("Found error:" + Str(nErr) + "," + errMsg)
   Else
       MsgBox ("Succeed in payment.add")
   End If

   'disconnect the company object, and release resource
   Call vCompany.Disconnect
   Set vCompany = Nothing
   Exit Sub
ErrorHandler:
   MsgBox ("Exception:" + Err.Description)
End Sub